program lagrange_interpolation
implicit none
  integer :: n,maxi,i,j
  real::xp,fp,lf,su
  real,allocatable,dimension(:)::x
  real,allocatable,dimension(:)::f
  print*,'number of data points'
  read*,n

  allocate(x(n))
  allocate(f(n))

  print*,'Input data points and the function value(x(i) y(i))'
  do i=1,n
    read*,x(i),f(i)
  end do

  print*,'Co-ordinate at which function value is required'
  read*,xp

  su = 0.0

  do i=1,n
    lf = 1.0
    do j=1,n
     if(i/=j)then
       lf = lf*(xp - x(j))/(x(i) - x(j))
     end if
    end do
    su = su + lf*f(i)
  end do
  fp = su
  print*, 'LAGRANGIAN INTERPOLATION'
  print*, 'interpolated function value at:',xp
  print*,fp
end program
